perm filename GUIDE.QLG[P,JRA] blob
sn#517264 filedate 1980-06-20 generic text, type T, neo UTF8
User's guide to the Qlog Lisp Machine Lisp system
CONTENT:
Qlog Syntax
Top Level
Interaction with the User
Asserting and Retracting Clauses
Pretty Printing
Interface between Lisp and Qlog
Running the System
QLOG SYNTAX
Horn clauses are usually written in the following way:
P(x,y) <- Q(x,z), R(y,z), S.
The interpratation is:
For all x, y, z [ P(x,y) if Q(x,z) and R(y,z) and S ]
Such the clause is written in Qlog as follows:
((p ?x ?y)
(q ?x ?z)
(r ?y ?z)
(s))
The case (upper either lower) is unimportant.
(p ?x ?y) is called the head of the clause;
the remaining elements of the list constitute the body.
A Qlog procedure usually consists of several alternatives. E.G.
(head1
body1)
(head2
body2)
...
(headn
bodyn)
A body might be empty.
Cut operator is represented by a form (cut).
Evaluating form (fail) forces immediate failure.
List Notation
There is a pecial convention for lists in Qlog. It is quite similar to the
dotted pair convention in Lisp. Since Qlog uses prefix notation one could
write a list (A B C) as (. A (. B (. C ()))). The list convention provides
a shorter and more legible notation. The list is writtten (@ A B C). The
empty list is annotated in Qlog as (@).
Segments are marked with ! E.g (@ ?KAR !?TAIL) matches the list (@ A B C)
with the following substitutions:
KAR <<= A
TAIL <<= (@ B C)
Note
It seems strange to represent lists in Lisp, but the pattern matcher must
somehow know about them. It is in some sense quoting or changing the standard
action of the pattern matcher.
TOP LEVEL
Assumming that the system is already loaded into the core (by executing
(pkg-load 'qlog)) call top level read-eval-print loop: (qlog). The prompt
character > will appear on the screen and you can enter Qlog forms.
STOP typed into Qlog will return to the Lisp top level. However
you can also evaluate Lisp forms under the Qlog top level.
Note
The Qlog top level is introduced since I need to reinitialize two variables,
CLOSURE and TOPCLOSURE, after Qlog form was evaluated. In Interlisp there
is an easy way to achieve it by means of LISPXUSERFN.
INTERACTION WITH THE USER
Usually the system writes OK which means that a solution for the goal is found.
Then it prints variables appearing in the goaland their respective bindings, and asks:
More ?. If you want the system to find the next solution type y, otherwise
type n.
The standard interaction is changed via setting a global variable ALLFLG.
It is initially set to nil. Changing its value to a non-nil value will prohibit the
system to ask. Instead, all solutions of the goal will be printed. Be cautious,
there might be an infinite number of solutions!
BREAKING QLOG FUNCTIONS
Do the regular (TRACE (fname BREAK T)) and use the following:
(DOR) - displays Dynamic OR stack
(LOR) - displays Lexical OR stack
(AND<) - displays AND stack
Hint: Put break on MOTHER and call (GRANDPARENT ?X JAN). In the second call
to MOTHER you'll see the difference between DOR and LOR.
ASSERTING AND RETRACTING CLAUSES
There are five functions which asserts clauses:
MA, AA, AZ, ASSERTA, ASSERTZ.
(MA
clause1
clause2
...
clausen)
MA is used to assert the whole definition of a given procedure.
It usually is used to write a definition from the editor but of course
may be used on the top level too.
The flag reassert-flg is set initially to T and the system will
first clear the previous definition and then assert the new one. If you
want to change it set the flag to nil.
(AA clause), (AZ clause)
These functions assert one clause at a time. The former one as the first
clause in the definition of the procedure, the latter as the last one. They
have the same effect if it happens that procedure is being defined for the
first time. Both should be used only on the top level.
(ASSERTA clause), (ASSERTZ clause)
These are similar functions to AA and AZ but should be rather used
by Qlog procedures to store side effects.
There are two functions which retract clauses: RETRACTA, RETRACTZ.
(RETRACTA clause), (RETRACTZ clause)
The former searches from the beginning, the latter from the end. Both
delete first clause (in order of the search) unifiable with the argument.
*** not implemented yet ***
PRETTY PRINTING
The function PP does the job of grindef for Qlog functions.
INTERFACE BETWEEN LISP AND QLOG
From Qlog to Lisp
(lisp form1 form2 ... formn)
While in the body of a Qlog procedure the user may specifie a call
to a Lisp function. The interpreter must be informed that a Lisp
(not a Qlog) function is to be evaluated. Forms are closed in the current
closure and evaluated (under apply). The most common application of
lisp function is for I/O functions.
From Lisp to Qlog
(qlog &optional "e qform &optional "e qfn# &optional "e &rest tuple#)
If called without arguments enters the regular read-eval-loop.
While inside Lisp function the user wants rather to save the result
of a computation for example on a variable. This is done by qlog
function called with other arguments specified.
Example 1
(qlog (grandparent ?xx stan) store-on-var my-var)
(GRANDPRENT ANN STAN)
my-var
(GRANDPARENT ANN STAN)
OBS! Only the first solution is found.
Example 2
(qlog (grandparent ?bb stan) store-on-prop stanley gprnts)
((GRANDPARENT ANN STAN)(GRANDPARENT HENRIETTE STAN)(GRANDPARENT
VICTOR STAN)(GRANDPARENT GEORGE STAN))
(get 'stanley 'gprnts)
((GRANDPARENT ANN STAN)(GRANDPARENT HENRIETTE STAN)(GRANDPARENT
VICTOR STAN)(GRANDPARENT GEORGE STAN))
OBS! Here all the solutions are found and consequently added to the property list
of STANLEY under the indicator GPRNTS
Example 3
(qlog (grandparent ?? yy stan))
(GRANDPARENT ANN STAN)
RUNNING THE SYSTEM
(load "janko;start qlg")
From now on you are in the QLOG package. Load the file JANKO;TEST QLG
and try to run the functions defined there. Good luck!